﻿using Crm.CrmClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Crm.Views
{
    public partial class CariFiltre : ChildWindow
    {
        public bool AdayCari { get; set; }
        public string Kodu { get; set; }
        public string Unvani { get; set; }
        public int ID { get; set; }

        public CariFiltre()
        {
            InitializeComponent();
            txtKodu.KeyDown += txtKodu_KeyDown;
            txtUnvan1.KeyDown += txtUnvan1_KeyDown;
        }

        void txtUnvan1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.F10)
            {
                adinaGoreAra();
            }
        }

        void txtKodu_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.F10)
            {
                kodunaGoreAra();
            }
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            kodunaGoreAra();
        }

        private void kodunaGoreAra()
        {
            PopupList list = new PopupList();
            list.ListeTipi = PopupListeTipleri.CariVeAday;
            list.KodunaGore = true;
            list.Filtre = txtKodu.Text.Replace('*', '%');
            list.Closed += list_Closed;
            list.Show();
        }

        void list_Closed(object sender, EventArgs e)
        {
            PopupList ls = (PopupList)sender;
            if (ls.DialogResult == true)
            {
                txtKodu.Text = ls.Result["Kodu"].ToString();
                txtUnvan1.Text = ls.Result["Adi"].ToString();
                this.ID = Convert.ToInt32(ls.Result["ID"]);
                if (ls.Result["HesapTipi"].ToString() == "Aday")
                {
                    this.AdayCari = true;
                }
                else
                {
                    this.AdayCari = false;
                }
                this.Kodu = ls.Result["Kodu"].ToString();
                this.Unvani = ls.Result["Adi"].ToString();
            }
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            adinaGoreAra();
        }

        private void adinaGoreAra()
        {
            PopupList list = new PopupList();
            list.ListeTipi = PopupListeTipleri.CariVeAday;
            list.KodunaGore = false;
            list.Filtre = txtUnvan1.Text.Replace('*', '%');
            list.Closed += list_Closed;
            list.Show();
        }
    }
}

